<template>
  <div class="mainContainer">
    <div class="left">
      <el-input
        placeholder="输入关键字进行过滤"
        v-model="filterText"
        style="margin-bottom: 10px"
      >
      </el-input>
      <el-tree
        class="filter-tree"
        :data="data"
        :props="defaultProps"
        accordion
        :filter-node-method="filterNode"
        @node-click="turn"
        ref="tree"
      >
      </el-tree>
    </div>
    <div class="right">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="编号" type="index"> </el-table-column>
        <el-table-column label="标题" prop="title"> </el-table-column>
        <el-table-column label="标签" prop="type"> </el-table-column>
        <el-table-column align="right">
          <template slot="header">
            <el-input
              v-model="search"
              size="mini"
              placeholder="输入关键字搜索"
            />
          </template>
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
              >查看详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // tableData: [{
      // date: '2016-05-02',
      // name: '王小虎',
      // address: '上海市普陀区金沙江路 1518 弄'
      // }, {
      // date: '2016-05-04',
      // name: '王小虎',
      // address: '上海市普陀区金沙江路 1517 弄'
      // }, {
      // date: '2016-05-01',
      // name: '王小虎',
      // address: '上海市普陀区金沙江路 1519 弄'
      // }, {
      // date: '2016-05-03',
      // name: '王小虎',
      // address: '上海市普陀区金沙江路 1516 弄'
      // }],
      search: "",
      tableData: null,
      filterText: "",
      data: [
        {
          id: 1,
          label: "2021年下学期",
          children: [
            {
              id: 9,
              label: "机械一班",
            },
            {
              id: 10,
              label: "机械三班",
            },
          ],
        },
        {
          id: 1,
          label: "2021年上学期",
          children: [
            {
              id: 9,
              label: "计算机一班",
            },
            {
              id: 10,
              label: "计算机三班",
            },
          ],
        },
        {
          id: 1,
          label: "2020年上学期",
          children: [
            {
              id: 9,
              label: "电气一班",
            },
            {
              id: 10,
              label: "电气三班",
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  mounted() {
    // axios也是可以直接用的，只不过我们要在这个页面里面进行import
    // axios
    //     .get('http://localhost:8282/question/list')
    //     // .then(function (response) {
    //     //     this.tableData = response.data
    //     //     console.log(this.tableData)
    //     // })
    // 这里有一个陷阱，就是我们必须要用下面这个格式  => 否则就会报错说明this is undefine
    //     .then(response => (this.tableData = response.data))
    //     .catch(function (error){
    //         console.log(error)
    //     })
    //     .then(function (){
    //         console.log("请求题目数据成功")
    //     })
    this.$http
      .get("question/list")
      // .then(function (response) {
      //     this.tableData = response.data
      //     console.log(this.tableData)
      // })
      .then((response) => (this.tableData = response.data))
      .catch(function (error) {
        console.log(error);
      })
      .then(function () {
        console.log("请求题目数据成功");
      });
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    turn(data) {
      this.$message("成功转到" + data.label + "该结点");
    },
  },
};
</script>

<style lang="less" scoped>
.mainContainer {
  height: 100%;
  width: 100%;
  display: flex;
}
.left {
  height: 100%;
  width: 20%;
  display: block;
  padding: 10px;
}
.right {
  height: 100%;
  width: 80%;
  display: flex;
  padding: 10px;
}
</style>>